package com.slkj.shilixiaoyuanapp.ui.user.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.entity.MyclassEntity;

import java.util.ArrayList;
import java.util.List;


public class MyClassAdapter extends BaseQuickAdapter<MyclassEntity,BaseViewHolder> {
    private Context context;
    private List<MyclassEntity> picPaths = new ArrayList<>();
    private onCheckLisener onCheckLisener;

    public void setOnCheckLisener(onCheckLisener onCheckLisener) {
        this.onCheckLisener = onCheckLisener;
    }

    public MyClassAdapter(@Nullable List<MyclassEntity> picPaths, Context context) {
        super(R.layout.item_my_class, picPaths);
        this.context = context;
        this.picPaths = picPaths;
    }
    @Override
    protected void convert(BaseViewHolder helper, MyclassEntity item) {
        ImageView checkBox = helper.getView(R.id.check);
        if (item.isChoose()){
            checkBox.setImageResource(R.drawable.choice_yes);
        }else {
            checkBox.setImageResource(R.drawable.choice_no);
        }
        TextView textView = helper.getView(R.id.name);
        textView.setText(item.getClassname());
        checkBox.setTag(R.id.id_choose_class_check_box,helper.getPosition());
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isChecked = item.isChoose();
//                if (!isChecked) {
                    isChecked = !isChecked;
//                    item.setChoose(isChecked);
                    onCheckLisener.OnCheckedListener(item, isChecked);
//                    notifyDataSetChanged();
//                }
            }
        });
    }


    public interface onCheckLisener{
        void OnCheckedListener(MyclassEntity chooseAddres, boolean checked);
    }
}
